package com.zhihaoliang.animationtrain.transition

import android.content.Intent
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityOptionsCompat
import androidx.core.util.Pair
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration
import com.zhihaoliang.animationtrain.R
import com.zhihaoliang.animationtrain.annotation.Info

@Info("Activity 页面跳转动画", "Activity页面跳转展示关联的页面View")
class TransitionActivity : AppCompatActivity(),ITranstionCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.transition_activity)

        val list:MutableList<TransitionBean> = mutableListOf(
            TransitionBean(R.mipmap.transition_ball,"球","张三",R.string.transition_info),
            TransitionBean(R.mipmap.transition_block,"长方体","李四",R.string.transition_info),
            TransitionBean(R.mipmap.transition_ducky,"小鸭子","王五",R.string.transition_info),
            TransitionBean(R.mipmap.transition_jellies,"安卓","赵六",R.string.transition_info),
            TransitionBean(R.mipmap.transition_mug,"谷歌","老七",R.string.transition_info),
            TransitionBean(R.mipmap.transition_pencil,"圆珠笔","老八",R.string.transition_info),
            TransitionBean(R.mipmap.transition_scissors,"剪刀","一哥",R.string.transition_info),
            TransitionBean(R.mipmap.transition_woot,"记事本","二弟",R.string.transition_info)

        )

        val recyclerView = findViewById<RecyclerView>(R.id.rcl_transition)
        recyclerView.layoutManager = GridLayoutManager(this, 2)
        recyclerView.addItemDecoration(
            HorizontalDividerItemDecoration.Builder(this)
                .color(Color.LTGRAY)
                .sizeResId(R.dimen.divider)
                .marginResId(R.dimen.divider_margin, R.dimen.divider_margin)
                .build()
        )
        recyclerView.addItemDecoration(
            VerticalDividerItemDecoration.Builder(this)
                .color(Color.LTGRAY)
                .sizeResId(R.dimen.divider)
                .marginResId(R.dimen.divider_margin, R.dimen.divider_margin)
                .build()
        )

        recyclerView.adapter = TranstionAdapter(list,this)
    }

    override fun onClick(view: View, transitionBean: TransitionBean) {
        val  intent = Intent(this,TransitionDetailActivity::class.java)
        intent.putExtra(KEY_TRANSITION,transitionBean)

        val activityOption = ActivityOptionsCompat.makeSceneTransitionAnimation(
            this,
            Pair(view.findViewById(R.id.transition_igv_image), TRANSITION_IMAGE),
            Pair(view.findViewById(R.id.transition_tv_title), TRANSITION_TEXT)
        )

        ActivityCompat.startActivity(this,intent,activityOption.toBundle())
    }
}
